package com.liuning.graduationdemo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import com.liuning.graduationdemo.service.IDoctorDepartmentService;
import com.liuning.graduationdemo.entity.DoctorDepartment;
import org.springframework.web.bind.annotation.RequestMapping;
import com.liuning.graduationdemo.common.Result;
import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 医生与科室关联表 前端控制器
 * </p>
 *
 * @author pumpkin
 * @since 2022-04-22
 */
@RestController
@RequestMapping("/doctor-department")
public class DoctorDepartmentController {

    @Resource
    private IDoctorDepartmentService doctorDepartmentService;

    /**
     * 保存或更新
     * @param doctorDepartment
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody DoctorDepartment doctorDepartment) {
        return Result.success(doctorDepartmentService.saveOrUpdate(doctorDepartment));
    }

    /**
     * 删除单条数据
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        doctorDepartmentService.removeById(id);
        return Result.success();
    }

    /**
     * 查询全部数据
     * @return
     */
    @GetMapping
    public Result findAll() {
        return Result.success(doctorDepartmentService.list());
    }

    /**
     * 根据id查询一条数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(doctorDepartmentService.getById(id));
    }

    /**
     * 分页查找所有数据
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
        QueryWrapper<DoctorDepartment> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return Result.success(doctorDepartmentService.page(new Page<>(pageNum, pageSize),queryWrapper));
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("/del/batch")
    public Result batchDelete(@RequestBody List<Integer> ids) {
        doctorDepartmentService.removeBatchByIds(ids);
        return Result.success();
    }


}

